package shotgun.my.sweetutil.mytest;

import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class MusicScanUtil {

    public static void main(String[] args) {
        //扫描目录
        String dirPath = "D:\\appData\\qqmusic";
        //扫描文件类型
        List<String> scanTypes = Stream.of("mflac", "qmcflac", "mgg").collect(Collectors.toList());


        File dir = new File(dirPath);

        File[] files = dir.listFiles();

        if (files != null && files.length > 0) {

            List<File> collectList = Arrays.stream(files).filter(file -> scanTypes.contains(getFileType(file.getName()))).collect(Collectors.toList());

            collectList.forEach(file -> System.out.println(file.getAbsolutePath()));

            System.out.println("文件数量：" + collectList.size());
            System.out.println("执行完毕 end...");
        }
    }

    public static String getFileType(String fileName) {
        int i = fileName.lastIndexOf(".");
        return i > -1 ? fileName.substring(i + 1) : fileName;
    }

    public static String getFileNameExcludeType(String fileName) {
        int i = fileName.lastIndexOf(".");
        return i > -1 ? fileName.substring(0, i) : fileName;
    }


}
